package com.neuedu.javase.tools.date;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/***
 * 项目名称:  MyJavaSE 
 * 包：  com.neuedu.javase.tools.date 
 * date:   2025/10/30   14:24  
 * 描述:  
 *  @author : 张金山
 *  作者博客:   https://blog.fulfill.com.cn
 */
public class FommatDate {
    public static void main(String[] args) {

        Date now = new Date();
        //   now   ---->  YYYY-MM=dd HH:mm:ss xzxxx


        // DateFormat  ->   SimpleDateFormat
        /**
         * Letter  Date or Time Component  Presentation  Examples
         * G  Era designator  Text  AD
         * y  Year  Year  1996; 96
         * Y  Week year  Year  2009; 09
         * M  Month in year (context sensitive)  Month  July; Jul; 07
         * L  Month in year (standalone form)  Month  July; Jul; 07
         * w  Week in year  Number  27
         * W  Week in month  Number  2
         * D  Day in year  Number  189
         * d  Day in month  Number  10
         * F  Day of week in month  Number  2
         * E  Day name in week  Text  Tuesday; Tue
         * u  Day number of week (1 = Monday, ..., 7 = Sunday)  Number  1
         * a  Am/pm marker  Text  PM
         * H  Hour in day (0-23)  Number  0
         * k  Hour in day (1-24)  Number  24
         * K  Hour in am/pm (0-11)  Number  0
         * h  Hour in am/pm (1-12)  Number  12
         * m  Minute in hour  Number  30
         * s  Second in minute  Number  55
         * S  Millisecond  Number  978
         * z  Time zone  General time zone  Pacific Standard Time; PST; GMT-08:00
         * Z  Time zone  RFC 822 time zone  -0800
         * X  Time zone  ISO 8601 time zone  -08; -0800; -08:00
         */
        // String pattern = "yyyy-MM-dd HH:mm:ss";
        // String pattern = "yyyy/MM/dd HH:mm:ss";
        // String pattern = "yyyy-MM-dd ";
        // String pattern = "yyyy/MM/dd ";
        String pattern = "yyyy年MM月dd日 HH时mm分 ss秒";
        // String pattern = "HH:mm:ss yyyy-MM-dd ";

        SimpleDateFormat sdf = new SimpleDateFormat(pattern);

        //使用sdf  格式化对象  变成 字符串
        String formatDate2Str = sdf.format(now);
        System.out.println(formatDate2Str);

        //使用sdf  字符串   变成  Date对象
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String inputDate = "05-06 18:35:26";    //正确的 日期  1977-05-06 18:35:26

        try {
            Date parseDate = sdf2.parse(inputDate);
            System.out.println("str 2 Date : "+parseDate);
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }

        /**
         * Exception in thread "main" java.lang.RuntimeException: java.text.ParseException: Unparseable date: "05-06 18:35:26"
         * 	at com.neuedu.javase.tools.date.FommatDate.main(FommatDate.java:71)
         * Caused by: java.text.ParseException: Unparseable date: "05-06 18:35:26"
         * 	at java.base/java.text.DateFormat.parse(DateFormat.java:399)
         * 	at com.neuedu.javase.tools.date.FommatDate.main(FommatDate.java:68)
         */


    }
}
